package dead;

import java.net.*;
import java.io.*;

import android.util.Log;

public class UDPReceiver {
	int port;
	
	public UDPReceiver(int port) {
		this.port = port;
	}
	
	public void receive() {
		DatagramSocket socket;
		try {
			socket = new DatagramSocket(port);
		} catch (SocketException e) {
			Log.e("UDPError", e.getMessage());
			return;
		}
		
		try {
			while (true) {
				byte[] buffer = new byte[1024];
				DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
				socket.receive(packet);
				Log.i("MessageReceived", new String(packet.getData()));
			}
		}
		catch (IOException e) {
			Log.e("UDPError", e.getMessage());
		}
		
		socket.close();
	}
}
